const {
  getColorHexRGB,

  darwinGetScreenPermissionGranted,
  darwinRequestScreenPermissionPopup
} = require('electron-color-picker');
const os = require("os");

const isDarwin = os.platform === 'darwin';

window.colorpicker = async () => {
  try {
    window.rubick.hideMainWindow();
    window.rubick.setExpendHeight(60);
    if (isDarwin) {
      const permission = await darwinGetScreenPermissionGranted();
      if (!permission) {
        return darwinRequestScreenPermissionPopup();
      }
    }
    const result = await getColorHexRGB();

    if (result) {
      window.rubick.copyText(result);
      window.rubick.showNotification(`${result}, 取色成功！已复制剪切板`);
    }

    window.rubick.removePlugin();
  } catch (e) {
    console.log(e);
  }
}

